package com.shunde.xunjian.controller;

import com.shunde.xunjian.entity.ruoyi.SysUser;
import com.shunde.xunjian.entity.ruoyi.UserInfo;
import com.shunde.xunjian.service.impl.RedisServiceImpl;
import com.shunde.xunjian.service.impl.RuoyiServiceImpl;
import com.shunde.xunjian.util.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/Ruoyi")
public class RuoyiController {
    @Autowired
    private RuoyiServiceImpl ruoyiService;

    @Autowired
    private RedisServiceImpl redisService;


    /**
     * 测试接口，登录状态下获取我的信息
     * @param request
     * @return
     */
    @RequestMapping(value = "/getMyselfTest", method = RequestMethod.POST)
    public UserInfo getMyselfTest(HttpServletRequest request) {
        UserInfo userInfo = redisService.getSysUser(request);
        return userInfo;
    }


    /**
     * 登录接口
     * @param username
     * @param password
     * @return
     */
    @RequestMapping(value = "/loginIn", method = RequestMethod.POST)
    public ResponseEntity<Object> loginIn (String password, String username) {
        return ruoyiService.LoginIn(username, password);
    }

    /**
     * 退出登录
     */
    @RequestMapping(value = "/loginOut", method = RequestMethod.POST)
    public Object loginOut(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return ruoyiService.LoginOut(token);
    }


    /**
     * 获取字典内容
     * @return
     */
    @GetMapping("/get_dict")
    public String getDict() {
        return "Hello, World!";
    }

    /**
     * 获取所有用户
     * @return
     */
    @GetMapping("/get_user")
    public Object getUsers(){
        return ruoyiService.getUsers();
    }
}
